from django.db import models


# Create your models here.
class Host(models.Model):
    # hostname Host类的属性  也是表字段
    # models.CharField 提供了字段的类型 char()
    # create table host(
    # id int ungisned auto_increment primary key,
    # hostname varchar(20) not null,
    # ip varchar(16) not null,
    # type int not null,
    # status int not null
    # )engine=innodb,charset=utf8
    # id = models.IntegerField(primary_key=True)
    # 主机类型 1-web 2-db 3-proxy 4-lb 5-cache
    type_tuple = ((1, 'web'), (2, 'db'), (3, 'proxy'), (4, 'lb'), (5, 'cache'))
    # 状态类型  0 在线  1 下线
    status_tuple = ((0, 'up'), (1, 'down'))
    hostname = models.CharField(max_length=20, unique=True, verbose_name='主机名称')
    ip = models.CharField(max_length=16, verbose_name='主机IP')
    type = models.IntegerField(choices=type_tuple, verbose_name='主机类型')
    status = models.IntegerField(choices=status_tuple, verbose_name='主机状态')

    def __str__(self):
        return self.hostname

    class Meta:
        # 默认不设置  表名称为app_模型名称
        # db_table = 'host'
        # 字段排序  - 倒序
        # ordering = ['-hostname']
        verbose_name = '主机信息表'


# 创建一张学生表 student
# 字段  sno name age sex
sex_tuple = ((1, '男'), (2, '女'), (3, '保密'))


class Student(models.Model):
    sno = models.AutoField(primary_key=True, verbose_name='学号')
    name = models.CharField(max_length=20, verbose_name='姓名')
    age = models.IntegerField(verbose_name='年龄')
    sex = models.IntegerField(choices=sex_tuple, verbose_name='性别')

    class Meta:
        db_table = 'student'
        verbose_name = '学生信息表'


class MyUser(models.Model):
    email = models.EmailField(verbose_name='邮件地址')
    status = models.BooleanField(verbose_name='状态')


class Student1(models.Model):
    name = models.CharField(max_length=20, verbose_name='学生姓名')

    class Meta:
        db_table = 'student1'


# 图书表
class Book(models.Model):
    name = models.CharField(max_length=50,verbose_name='图书名称')
    # digits 整数和小数部分  数字总数    decimal_places 小数保留位数
    price = models.DecimalField(max_digits=5, decimal_places=2)
    # 一对多关系
    publish = models.ForeignKey('Publish')
    # 多对多关系

# 出版社表
class Publish(models.Model):
    name = models.CharField(max_length=50,verbose_name='出版社名称')
    address = models.CharField(max_length=100,verbose_name='出版社地址')

# 作者表
class Author(models.Model):
    name = models.CharField(max_length=50,verbose_name='作者姓名')
    job = models.CharField(max_length=50,verbose_name='工种')